package com.dscs.service.impl;

import com.dscs.domain.Role;
import com.dscs.mapper.RoleMapper;
import com.dscs.service.IRoleService;
import com.dscs.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 叶雪娟
 * @date 2019/7/17
 **/
@SuppressWarnings("ALL")
@Service
public class RoleServiceImpl implements IRoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> queryAllRole() {
        return roleMapper.queryAllRole();
    }

    @Override
    public Msg insertRole(Role role) {
        Msg m = new Msg();
        long i = roleMapper.insertRole(role);
        if (i > 0) {
            m.setMsg("插入成功。");
            m.setStatus(true);
        } else {
            m.setMsg("插入失败。");
            m.setStatus(false);
        }
        return m;
    }

    @Override
    public Msg deleteRole(Long id) {
        Msg m = new Msg();
        long j = roleMapper.deleteRole(id);
        if (j > 0) {
            m.setMsg("删除成功。");
            m.setStatus(true);
        } else {
            m.setMsg("删除失败。");
            m.setStatus(false);
        }
        return m;
    }

    @Override
    public Msg updateRole(Role role) {
        Msg m = new Msg();
        long k = roleMapper.updateRole(role);
        if (k > 0) {
            m.setMsg("更新成功。");
            m.setStatus(true);
        } else {
            m.setMsg("更新失败。");
            m.setStatus(false);
        }
        return m;
    }
}
